﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using PGMHelper;

namespace WSAP
{
    /// <summary>
    /// 结构信息
    /// </summary>
    class Structure
    {
        /// <summary>
        /// 楼层列表
        /// </summary>
        private List<Storey> storeyList { set; get; }

        /// <summary>
        /// 楼层数量
        /// </summary>
        public int Count
        {
            get
            {
                return this.storeyList.Count;
            }
        }

        /// <summary>
        /// 添加楼层
        /// </summary>
        /// <param name="stiff"></param>
        /// <param name="mass"></param>
        public void AddStorey(double stiff, double mass)
        {
            this.storeyList.Add(new Storey(this.Count + 1, stiff, mass));
        }

        /// <summary>
        /// 清空列表
        /// </summary>
        public void Clear()
        {
            this.storeyList = new List<Storey>();
        }

        /// <summary>
        /// 获得绘图数据
        /// </summary>
        /// <returns></returns>
        public GridViewDatas GetData()
        {
            var data = new GridViewDatas();
            //楼层编号列表
            var storeyList = (from storey in this.storeyList select storey.StoreyIndex).ToList();
            var massList = (from storey in this.storeyList select storey.Mass).ToList();
            var stiffList = (from storey in this.storeyList select storey.Stifffness).ToList();
            //添加列
            data.Add(new GridViewColumn(storeyList, titleName: "楼层", 80));
            data.Add(new GridViewColumn(massList, titleName: "质量(t)", width:120));
            data.Add(new GridViewColumn(stiffList, titleName: "刚度(MN/M)", width: 120));
            return data;
        }

        /// <summary>
        /// 获得有限元模型
        /// </summary>
        /// <returns></returns>
        public void DoEigen(int eigenNumber)
        {
            //初始化
            var model = new WModelNet();
            //遍历添加楼层
            this.storeyList.ForEach(storey => model.AddDOF(storey.Mass, storey.Stifffness * 1E3));
            //创建有限元模型
            if (!model.CreateFEModel(false)) model.ShowWarningError();
            //模态分析
            var periodList = model.DoEigen(eigenNumber);
            //显示模态分析结果
            WSAPHelper.ShowPeriodInfo(periodList);
            //绘图
            model.ToDynamicGraphics(new StructrueChartParam(StructureChartType.Eigen));
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        public Structure()
        {
            this.storeyList = new List<Storey>();
        }
    }
}
